var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
    return typeof t;
  } : function(t) {
    return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
  },
  app = getApp(),
  that,
  dataheith = [0],
  linheightid = 0;
let $this;
var that;
Page({
  data: {
    tabs: ['爱车头条', '爱车百科'],
    currentTab: '',
    items: [],
    showModal: !1,
    indicatorDots: false,
    autoplay: false,
    interval: 4000,
    duration: 1000,
    page: 1,
    rows: 10,
    row: 10,
    carNewsData: [],
    loveBookTab: [],
    loveBook: [],
    // lowerId: '',
    // 爱车百科
    linheightid: linheightid,
    scroll: "scroll",
    store: {
      cat_style: 4
    },
    currentId: {},
    loveBooks: '',
    itemId:'',
    carBible: [],
    carBibleBanner:[],
    shopId:'',
    isLoadMore:false,
    memberId:''
  },
  yczz: function() {
    this.setData({
      showModal: !1
    });
  },
  onLoad: function(o) {
    that = this
  },
  onReady: function() {},
  onShow: function() {
    this.setData({
      indicatorDots: !this.data.indicatorDots,
      autoplay: !this.data.autoplay,
      shopId: wx.getStorageSync('shopData').id,
      memberId: wx.getStorageSync('bizUserInfo').id
    });
    that.getCarNews();
    that.getLoveBook();
    that.getLoveBookTab();
    that.carBibleBanner();
  },
  swichNav: function(e) {
    console.log(e);
    var that = this;
    console.log(e.currentTarget.dataset.index);
    if (e.currentTarget.dataset.index==1){
      console.log("loveboo===" + JSON.stringify(that.data.loveBookTab[0].id));
      that.getLoveBookss(that.data.loveBookTab[0].id)
    }
    if (that.data.currentTab === e.currentTarget.dataset.index) {
     
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.index,
      })
      
      console.log(that.currentTab);
    }
   
  },
  swiperChange: function(e) {
    console.log(e);
    if (e.detail.current == 1) {
      console.log("loveboo===" + JSON.stringify(that.data.loveBookTab));
      this.getLoveBookss(this.data.loveBookTab[0].id)
    }
    this.setData({
      currentTab: e.detail.current,
    })
  },
  catItemClick: function(t) {
    console.log("t==="+JSON.stringify(t))
    var e = this;
    console.log("你点击的ID为：",t.currentTarget.dataset.id);
    var o = t.currentTarget.dataset.id;
    var h = t.currentTarget.dataset.index;
    console.log(void 0 === o ? "undefined" : _typeof(o)), e.updateSelectedPage(parseInt(o)),
      this.setData({
        intoid: "id" + o,
        linheightid: o,
        scroll: "",
        loveBooks:h,
      }), setTimeout(function() {
        e.setData({
          scroll: "scroll"
        });
      }, 500);
    e.getLoveBook();
  },
  scroll: function(t) {
    console.log(t);
    for (var e = t.detail.scrollTop, o = (t.detail.scrollTop, 0); o < dataheith.length; o++)
      if (e <= dataheith[o - 1]) {
        if (console.log(o), console.log(e, linheightid), linheightid != o) {
          if (this.updateSelectedPage(o - 2), -1 == (linheightid = o - 2)) return void this.setData({
            linheightid: 0
          });
          this.setData({
            linheightid: linheightid
          });
        }
        break;
      }
  },
  updateSelectedPage: function(t) {
    console.log("====_updateSelectedPage", t);
    // that.getLoveBook(t)
    var e = this.data,
      o = e.window_height,
      i = e.loveBookTab,
      a = (i.item_width, Math.round(o / i.item_height)),
      n = i.item_height * (t - a + 1),
      l = i.item_height * t;
    (i.tab_left < n || i.tab_left > l) && (i.tab_left = l - (o - i.item_height) / 2),
    console.log(i),
      this.setData({
        tab_config: i
      });
  },
  getCarNews: function() {
    app.getData({
      url: app.api.getCarNews(89, that.data.memberId,that.data.page, that.data.rows),
      method: 'GET',
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            if (that.data.page == 1) {
              that.data.carNewsData = []
            }
            if (res.data.list.length < that.data.rows) {
              that.setData({
                carNewsData: that.data.carNewsData.concat(res.data.list),
                isLoadMore: false
              })
            } else {
              that.setData({
                carNewsData: that.data.carNewsData.concat(res.data.list),
                isLoadMore: true,
                page: that.data.page + 1
              })
            }
          }
        }
      }
    })
  },
  itemClick: function(e) {
    console.log(JSON.stringify(e.currentTarget.dataset.item))
    wx.navigateTo({
      url: '../../pages/newsDetails/newsDetails?item=' + encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item)),
    })
  },
  getLoveBook: function() {
    var that = this;
    app.getData({
      url: app.api.getCarNews(that.data.linheightid, wx.getStorageSync('bizUserInfo').id, 1, 10),
      method: 'GET',
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            console.log(res.data.list)
            that.setData({
              loveBook: res.data.list,
            });
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        };
      }
    })
  },
  getLoveBookss: function (e) {
    var that = this;
    app.getData({
      url: app.api.getCarNews(e, that.data.memberId, 1, 10),
      method: 'GET',
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          // var h = t.currentTarget.dataset.index;
          if (res.data.code == 1) {
            console.log(res.data.list)
            that.setData({
              //详情返回无
              intoid: "id" + res.data.list[0].articlelowerId,
              linheightid: res.data.list[0].articlelowerId,
              scroll: "",
              // loveBooks: h,
              loveBook: res.data.list
            });
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        };
      }
    })
  },
  getLoveBookTab: function(res) {
    app.getData({
      url: app.api.getLoveBookTab(82),
      method: 'GET',
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            console.log(res.data.data)
            that.setData({
              loveBookTab: res.data.data,
            });
            
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
  },
  //Banner
  carBibleBanner: function(res) {
    app.getData({
      url: app.api.getCarBible(that.data.shopId,3,1,10),
      method: 'GET',
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            that.setData({
             carBible: res.data.list
            })
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }

    });
  },
});